<template>
	<view class="menuList">
		<div class="title">
			请选择服务类型
<!--            <cover-image @click="linkTo" class="setImg"  src="../../static/setting.png"></cover-image>-->
            <image @click="linkTo" class="setImg" src="../../static/setting.png"></image>
        </div>
		<div class="content">

			<div class="menuListButton appointmentRegistration" @click="appointmentRegistration()">
				<span>
					<image src="../../static/icon_registered.png"></image>
				</span>预约挂号
			</div>
			<div class="menuListButton appointmentRegistration " @click="onlinePayment()">
				<span>
					<image src="../../static/icon_pay.png"></image>
				</span>在线缴费
			</div>
			<div class="menuListButton  onlinePayment" @click="caseSearch()">
				<span>
					<image src="../../static/icon_search.png"></image>
				</span>报告查询
			</div>
			<div class="menuListButton onlinePayment" @click="goToHospitalIntroduction()">
				<span>
					<image src="../../static/icon_search.png"></image>
				</span>医院简介
			</div>
			<div class="menuListButton caseSearch" @click="getArticleList(3)">
				<span>
					<image src="../../static/icon_search.png"></image>
				</span>科室介绍
			</div>
			<div class="menuListButton caseSearch" @click="getArticleList(4)">
				<span>
					<image src="../../static/icon_search.png"></image>
				</span>健康百科
			</div>
<!--            <div class="menuListButton caseSearch" @click="linkTo">-->
<!--				<span>-->
<!--					<image src="../../static/icon_search.png"></image>-->
<!--				</span>打印机配置-->
<!--            </div>-->
<!--            <div class="menuListButton caseSearch" @click="printText">-->
<!--				<span>-->
<!--					<image src="../../static/icon_search.png"></image>-->
<!--				</span>打印测试-->
<!--            </div>-->
		</div>
		<div class="qrCodeLogo">
			<image src="../../static/qrCodeLogo.jpg"></image>
			使用微信扫描上方二维码也可以进行在线操作
		</div>
	</view>
</template>

<script lang="ts">
	import { uiCollection } from '../../Providing/uiCollection';
	import { request } from '../../Providing/request'
	import { globalVariable } from '../../globalVariable/globalVariable';
	const plugin = uni.requireNativePlugin('getIdCardInformation');




	export default {
		data() {
			return {
			}
		},
		methods: {
            /*进入打印机配置界面*/
            linkTo(){
                uni.navigateTo({
                    // url: '/pages/printerSet/printerSet',
					url: '/pages/systemSet/systemSet'
                })
            },
            /*进入打印测试界面*/
            printText(){
                uni.navigateTo({
                    url: '/pages/printText/printText'
                })
            },
			manualInputIdCard(resolve) {
				uiCollection.enterIdCard().then(idCard => {
					if (idCard['status']) {
						if (idCard['status'] == true && idCard['idCard'] == '') {
							uiCollection.showToast("请输入正确身份证号")
							return
						} else {
							console.log("用户输入了正确身份证号", idCard)
							// new request().getHealthCard(idCard['idCard']).then((res) => {
							// 	uiCollection.hideLoading();
							// 	console.log(JSON.stringify(res));
							// 	globalVariable.brid = res['brid']
							// 	globalVariable.cardId = res['id']
							// 	globalVariable.realName = res['realName']
							// 	resolve(true);
							// }).catch((err) => {
							// 	uiCollection.showToast("请用微信扫描小程序二维码进行健康卡注册");
							// })
							globalVariable.iDCard = idCard['idCard'];
							this.verifyIdCard(resolve,idCard['idCard'])
						}
					}
				});
			},

			login() {

				return new Promise((resolve) => {
					uiCollection.showLoading('请将身份证放置在下方读卡处');

					plugin.sayHi("lance", (res) => {
						uiCollection.hideLoading()
						console.log("插件返回内容", JSON.stringify(res))
						if (res['status'] == "err") {

							// uiCollection.showToast(res['msg'])
							return this.manualInputIdCard(resolve)
						}

						globalVariable.peopleName = res['peopleName'];
						globalVariable.sex = res['sex'];
						globalVariable.people = res['people'];
						globalVariable.birthDay = res['birthDay'];
						globalVariable.addr = res['addr'];
						globalVariable.iDCard = res['iDCard'];
						this.verifyIdCard(resolve, res['iDCard'])

					})
				})


			},

			verifyIdCard(resolve, idCard : string) {
				uiCollection.showLoading("进行身份验证中");
				new request().getHealthCard(idCard).then((res) => {
					uiCollection.hideLoading();
					console.log(JSON.stringify(res));
					globalVariable.brid = res['brid']
					globalVariable.cardId = res['id']
					globalVariable.realName = res['realName']
					resolve(true);
				}).catch((err) => {
					uiCollection.hideLoading();
					console.log('返回err', err);
					uiCollection.showModal(err).then((res1) => {
						if (res1) {
							//读取身份证返回接口需要使用
							uni.$emit('goToHealthCardRegistration')

						};
					})
				})
			},

			appointmentRegistration() {

				this.login().then(res => {
					if (res == true) {
						uni.$emit('goToAppointmentRegistration')
					}
				})

			},

			onlinePayment() {

				this.login().then(res => {
					if (res == true) {
						uni.$emit('goToOnlinePayment')
					}
				})

			},

			caseSearch() {

				this.login().then(res => {
					if (res == true) {
						uni.$emit('goToCaseSearch')
					}
				})
			},
			goToHospitalIntroduction() {

				uni.$emit('goToHospitalIntroduction')
			},
			comeBack() {
				uni.$emit('goToHome');
			},
			getArticleList(id) {
				globalVariable.articleListId = id;
				uni.$emit('goToArticleList');
			}
		},
	}
</script>

<style lang="scss">
	.menuList {
		width: 100%;
		height: 800px;
		background-image: url("../../static/base_image.png");
		background-size: 100% 100%;

		.title {
			width: 100%;
			height: 80px !important;
			line-height: 80px;
			margin-left: 10px;
			color: #2f59f3;
			letter-spacing: 25px;
			text-indent: 10px;
			margin: auto;
			padding-left: 20px;
			background-color: #fff;
			font-size: 30px !important;
			image {
				width: 15px;
				height: 30px;
				top: 5px;
				float: left;
			}
            .setImg{
                margin-left: 50rpx;
                margin-top: 40rpx;
                width: 70rpx;
                height: 70rpx;
            }
		}

		.content {


			width: 100%;
			height: 400px;
			display: flex;
			flex-wrap: wrap;
			padding-top: 100px;

			.menuListButton {

				width: 250px;
				height: 90px;
				line-height: 90px;
				color: #fff;
				font-size: 20px;
				border-radius: 10px;
				margin: auto;

				span {
					width: 60px;
					height: 60px;
					display: inline-block;
					border-radius: 100%;
					vertical-align: middle;



					image {
						width: 35px;
						height: 35px;
						display: block;
						margin: 13px auto 0;
					}
				}

			}

			.appointmentRegistration {
				background-color: #ff6c00;
				text-align: center;

				span {
					background-color: #70300b70;
					margin-left: 10px;
					margin-right: 20px;
				}
			}

			.onlinePayment {
				background-color: #ffe500;
				text-align: center;

				span {
					background-color: #70300b70;
					margin-left: 10px;
					margin-right: 20px;
				}
			}

			.caseSearch {
				background-color: #a30fdf;
				text-align: center;

				span {
					background-color: #70300b70;
					margin-left: 10px;
					margin-right: 20px;
				}
			}

		}

		.qrCodeLogo {
			position: fixed;
			bottom: 0;
			width: 100%;
			font-size: 30px;
			color: #fff;
			margin: auto;
			text-align: center;

			image {
				width: 150px;
				height: 150px;
				display: block;
				margin: auto;

			}
		}

	}

</style>
